package Collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class GenericDemo {
    public static void main(String[] args) {
        Collection<priot> p = new ArrayList<>();
        p.add(new priot(1,2));
        p.add(new priot(12,24));
        p.add(new priot(13,26));
        p.add(new priot(14,28));
        Iterator<priot> iterator = p.iterator();
        while (iterator.hasNext()){
            priot p1 = iterator.next();
            System.out.println(p1);
        }
        for (priot priot:p){
            System.out.println(priot);
        }


        Collection<String> c = new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");
        //迭代器所指定的泛型应该和其遍历的集合的泛型一致
        Iterator<String> it  = c.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
        for (String str: c){
            System.out.println(str);
        }
    }
}
